package com.hjm.project.job.task.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.job.task.domain.JobTask;
import com.hjm.project.job.task.service.IJobTaskService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 文件下载队列Controller
 * 
 * @author maker-platform
 * @date 2021-01-16
 */
@Controller
@RequestMapping("/job/task")
public class JobTaskController extends BaseController
{
    private String prefix = "job/task";

    @Autowired
    private IJobTaskService jobTaskService;

    @RequiresPermissions("job:task:view")
    @GetMapping()
    public String task()
    {
        return prefix + "/task";
    }

    @RequiresPermissions("job:task:taskDate")
    @GetMapping("/taskDate")
    public String taskDate()
    {
        return prefix + "/taskData";
    }

    /**
     * 查询文件下载队列列表
     */
    @RequiresPermissions("job:task:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JobTask jobTask)
    {
        startPage();
        List<JobTask> list = jobTaskService.selectJobTaskList(jobTask);
        return getDataTable(list);
    }

    /**
     * 查询文件下载队列列表
     */
    @PostMapping("/dataList")
    @ResponseBody
    public TableDataInfo dataList(JobTask jobTask)
    {
        startPage();
        List<JobTask> list = jobTaskService.selectJobTaskListOfData(jobTask);
        return getDataTable(list);
    }


    /**
     * 查询文件下载队列列表
     */
    @RequiresPermissions("job:task:list")
    @PostMapping("/allList")
    @ResponseBody
    public TableDataInfo allList(JobTask jobTask)
    {
        startPage();
        List<JobTask> list = jobTaskService.selectAllJobTaskList(jobTask);
        return getDataTable(list);
    }

    /**
     * 导出文件下载队列列表
     */
    @RequiresPermissions("job:task:export")
    @Log(title = "文件下载队列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JobTask jobTask)
    {
        List<JobTask> list = jobTaskService.selectJobTaskList(jobTask);
        ExcelUtil<JobTask> util = new ExcelUtil<JobTask>(JobTask.class);
        return util.exportExcel(list, "task");
    }

    /**
     * 新增文件下载队列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文件下载队列
     */
    @RequiresPermissions("job:task:add")
    @Log(title = "文件下载队列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JobTask jobTask)
    {
        return toAjax(jobTaskService.insertJobTask(jobTask));
    }



    /**
     * 下载类型为导入文件的类型
     */
    @RequiresPermissions("job:task:add")
    @Log(title = "文件下载队列", businessType = BusinessType.INSERT)
    @PostMapping("/downUploadFile")
    @ResponseBody
    public AjaxResult downUploadFile(JobTask jobTask) {
        return toAjax(jobTaskService.insertJobTask(jobTask));
    }

    /**
     * 修改文件下载队列
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JobTask jobTask = jobTaskService.selectJobTaskById(id);
        mmap.put("jobTask", jobTask);
        return prefix + "/edit";
    }

    /**
     * 修改保存文件下载队列
     */
    @RequiresPermissions("job:task:edit")
    @Log(title = "文件下载队列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JobTask jobTask)
    {
        return toAjax(jobTaskService.updateJobTask(jobTask));
    }

    /**
     * 删除文件下载队列
     */
    @RequiresPermissions("job:task:remove")
    @Log(title = "文件下载队列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jobTaskService.deleteJobTaskByIds(ids));
    }
}
